package com.yami.shop.controller;

import com.yami.shop.bean.model.MeltCloudUser;
import com.yami.shop.common.bean.PageDTO;
import com.yami.shop.common.bean.PageVO;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.service.impl.RongYunUserWhiteServiceImpl;
import com.yami.shop.service.impl.RongYunWhiteListServiceImpl;
import com.yami.shop.vo.group.whitelist.WhitelistVo;
import com.yami.shop.vo.user.UserBlackVo;
import io.rong.models.response.GroupBanWhitelistResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/account/im/group/whitelist")
@Schema(description = "app-钱包IM禁言用户黑/白名单")
public class RongYunWhiteListController {
    @Autowired
    private RongYunWhiteListServiceImpl whiteListService;

    @Autowired
    private RongYunUserWhiteServiceImpl rongYunUserWhiteService;

    @PostMapping("/group_white_add")
    @Operation(summary =  "添加禁言白名单用户方法")
    public ServerResponseEntity<String> add(@RequestBody @Valid WhitelistVo groupVo) {
        return whiteListService.add(groupVo);
    }

    @GetMapping("/group_white_list")
    @Operation(summary =  "查询禁言白名单用户方法", description = "查询禁言白名单用户方法")
    public ServerResponseEntity<GroupBanWhitelistResult> getInfo(@RequestParam String groupId) {
        return whiteListService.getList(groupId);
    }


    @PostMapping("/group_white_remove")
    @Operation(summary =  "移除禁言白名单用户方法")
    public ServerResponseEntity<String> remove(@RequestBody @Valid WhitelistVo groupVo) {
        return whiteListService.remove(groupVo);
    }

    @GetMapping("/userBlacklistAdd")
    @Operation(summary =  "添加黑名单")
    public ServerResponseEntity<String> userBlacklistAdd(@RequestBody @Valid UserBlackVo groupVo) throws Exception {
        return rongYunUserWhiteService.userBlacklistAdd(groupVo.getUserId(),groupVo.getUserBlacklist());
    }

    @GetMapping("/removeBlack")
    @Operation(summary =  "移除黑名单")
    public ServerResponseEntity<String> removeBlack(@RequestBody @Valid UserBlackVo groupVo) throws Exception {
        return rongYunUserWhiteService.remove(groupVo.getUserId(),groupVo.getUserBlacklist());
    }

    @GetMapping("/queryBlacklist")
    @Operation(summary =  "黑名单列表")
    public ServerResponseEntity<PageVO<MeltCloudUser>> queryBlacklist(PageDTO pageDTO, @RequestParam("userId") String userId, @RequestParam("userName") String userName) throws Exception {
        return rongYunUserWhiteService.queryBlacklist(pageDTO,userId,userName);
    }

    @GetMapping("/queryisBlack")
    @Operation(summary =  "黑名单列表")
    public ServerResponseEntity<Boolean> queryisBlack(@RequestParam("userId") String userId, @RequestParam("touserId") String touserId){
        return rongYunUserWhiteService.queryisBlack(userId,touserId);
    }
}
